package com.tcp2.handler;


import com.tcp2.server.DxsConfig;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Author: 杨俊辉
 * Time: 2014-09-22 17:34
 * Copyright (C) 2014 Xiamen Yaxon Networks CO.,LTD.
 */

@Service
public class PlatformCacheServcie implements InitializingBean {
    @Override
    public void afterPropertiesSet() throws Exception {

    }


   /* //下级平台接入码关联下级平台对象
    private static ConcurrentMap<Integer, AccessPlatform> platformMap = new ConcurrentHashMap<>();
    //下级平台id关联下级平台对象
    private static ConcurrentMap<Long, AccessPlatform> platformMap2 = new ConcurrentHashMap<>();


    @Autowired
    private AccessPlatformDao accessPlatformDao;
    @Autowired
    private PlatformLinkLogDao platformLinkLogDao;


    @Autowired
    DxsConfig dxsConfig;

    @Override
    public void afterPropertiesSet() throws Exception {
       *//* String gs = dxsConfig();
        if (!Strings.isNullOrEmpty(gs)) {
            String[] ss = gs.split(",");
            for (String s : ss) {
                vehicleGroups.add(Long.parseLong(s));
            }
        }*//*
    }

    public AccessPlatform getPlatformByUser(Integer userId, String password) {
        AccessPlatform platform = accessPlatformDao.getPlatformByUser(userId.toString(), password);
        return platform;
    }

    public AccessPlatform getPlatformByUserName(Integer userId) {
        AccessPlatform platform = accessPlatformDao.getPlatformByUserName(userId.toString());
        return platform;
    }

    public AccessPlatform getUpPlatformByDistrictId(Long districtId, Byte accessType){
        AccessPlatform ap=accessPlatformDao.getUpPlatformByDistrictId(districtId,accessType);
        return ap;
    }

    public int insertPlatformLinkLog(PlatformLinkLog entity) {
        return platformLinkLogDao.insert(entity);
    }

    public AccessPlatform getPlatformByAccessCode(Integer accessCode) {
        AccessPlatform accessPlatform = platformMap.get(accessCode);
        if (accessPlatform == null){
            accessPlatform = accessPlatformDao.getAcessPlatformByAccessCode(String.valueOf(accessCode));
        }
        return accessPlatform;
    }

    public void setPlatform(AccessPlatform entity) {
         platformMap.put(Integer.valueOf(entity.getAcessCode()), entity);
         platformMap2.put(entity.getId(),entity);
    }

    public AccessPlatform getPlatformById(Long id) {
        AccessPlatform accessPlatform = platformMap2.get(id);
        if(accessPlatform == null) {
            accessPlatform = accessPlatformDao.get(id);
        }
        return accessPlatform;
    }

    public void removePlatformById(int id){
        AccessPlatform accessPlatform = platformMap.get(id);
        if(accessPlatform!=null){
            platformMap.remove(id);
        }
    }*/

}
